<?php
namespace app\thread\controller;
use think\Controller;
use app\thread\model\Thread as ThreadModel;
use org\util\HtmlPage;
use think\Db;
use think\Session;
use think\Request;
Session::get('user');

class Thread extends Controller{
    function index(){
        return view('thread');
    }
    function thread_list(){
        $m_id=input('get.id');
        //$m_id=input('m_id');
        /*
        $thread_res=ThreadModel::all(function ($query) use ($m_id){
           $query->where('m_id',$m_id)->limit(20)->order('last_time','desc');
        });
        */
        //$thread_res=ThreadModel::where('m_id',$m_id)->limit(20)->order('last_time','desc')->select();
        //$data['total']=ThreadModel::find()->count();
        //return $m_id;
        $data['total']=ThreadModel::where('m_id',$m_id)->count();
        //return $data['total'];
        //$data['total']=Db::name('thread')->where('m_id',$m_id)->count();
        //return $data['total'];
        //return $data['total'];
        $data['p']=!input('get.p')?1:input('get.p');
        $data['limit']=20;
        $data['page_start']=($data['p']-1)*$data['limit'];
        $data['method']='ajax';
        $data['js_method']='setpage';
        $request=Request::instance();
        $url=$request->baseUrl();
        $data['url']=$url.'?id='.$m_id.'&p=';
        $thread['content']=ThreadModel::where('m_id',$m_id)->limit($data['page_start'],$data['limit'])->order('last_time','desc')->select();
        $page_banner=new HtmlPage($data);
        $thread['banner']=$page_banner->banner_list();
        $m_id_name=Db::name('section')->where('id',$m_id)->value('name');
        $tou="<p><a href=\"/forum/index.php\" class=\"a1\">论坛首页</a>->>".$m_id_name."</p>";
        $thread['head_list']=$tou;
        $thread['total']=$data['total'];
        //return $thread['total'];
        $this->assign("thread_context",$thread['content']);
        $this->assign("thread_head",$thread['head_list']);
        $this->assign("page_banner",$thread['banner']);
        $this->assign("mid",$m_id);
        return $this->fetch('thread');
        //return $thread;

        //return $thread_res;
    }
}